package com.zyg.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyg.config.RabbitMQConfig;
import com.zyg.model.Result;
import com.zyg.model.UserInfo;
import com.zyg.mq.ZygMsgSender;
import com.zyg.util.UserInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

  /*  *//**
     * 测试抛出异常，异常全局捕捉
     * @return
     * @throws Exception
     *//*
    @GetMapping("/va/test")
    public Result TestVA() throws Exception {
        int i = 1/0;
        throw new Exception("抛出异常");
    }

    *//**
     * 测试接口
     * @return
     *//*
    @GetMapping("/vb/test")
    public Result TestVB(){
        return new Result().initSuccess();
    }

    @Autowired
    private UserService userService;

    *//**
     * 测试分页功能
     * @return
     *//*
    @GetMapping("/vc/test")
    public Result TestVC(){
        Page page = new Page(1,10);          //1表示当前页，而10表示每页的显示显示的条目数
        page = userService.selectUserPage(page);
        return new Result().initSuccess(page);
    }

    *//**
     * 测试使用mybatis plus自动生成创建时间、修改时间
     * @param id
     * @return
     *//*
    @GetMapping("/vd/test/{id}")
    public Result TestVD(@PathVariable String id){;
        return userService.deleteUserById(id);
    }

    *//**
     * 测试自动生成id 自动生成创建时间和删除状态
     * @param user
     * @return
     *//*
    @PostMapping("/ve/test")
    public Result TestVE(User user){;
        return userService.saveUserInfo(user);
    }

    @Autowired
    private ZygMsgSender zygMsgSender;

    *//**
     * 测试消息推送
     * @param user
     * @return
     *//*
    @PostMapping("/vf/test")
    public Result TestVF(User user){
        //推送对象
        zygMsgSender.sendUser(user, RabbitMQConfig.TOPIC_ZYG_DATA_MSG);
        //推送字符串
        zygMsgSender.send("test", RabbitMQConfig.TOPIC_ZYG_DATA_MSG);
        return new Result().initSuccess();
    }

    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("/vg/test")
    public Result TestVG(User user){
        redisTemplate.opsForValue().set("test", user);
        String userStr = redisTemplate.opsForValue().get("test").toString();
        User userTest= (User)redisTemplate.opsForValue().get("test");
        System.out.println(userStr);
        return new Result().initSuccess();
    }

    @PostMapping("/va/test/request-info")
    public Result requestInfo(){
        UserInfo userInfo = UserInfoUtil.getUser();
        return new Result().initSuccess();
    }*/
    /*
    public Page<User> selectUserPage(Page<User> page) {
        page.setRecords(baseMapper.selectUserList(page));
        return page;
    }

    public Result saveUserInfo(User user){
        baseMapper.insert(user);
        return new Result().initSuccess();
    }

    public Result deleteUserById(String id){
        baseMapper.deleteById(id);
        return new Result().initSuccess();
    }
     */
}
